package com.virtual.rerijaapps.pet.animation;

import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.OvershootInterpolator;
import android.view.animation.Transformation;

import com.androidquery.AQuery;
import com.virtual.rerijaapps.pet.R;
import com.virtual.rerijaapps.pet.SplashScreen;

public class MatrixAnimation 
{

	public static void applyAnimation( final SplashScreen splash, int viewId, final AQuery aquery ) 
	{
		
		RerijaMatrixAnimation animation = new RerijaMatrixAnimation();
		animation.setDuration( 3000 );
		animation.setFillAfter( true );
		animation.setInterpolator( new OvershootInterpolator() );
		
		animation.setAnimationListener( new AnimationListener() 
		{
			
			@Override
			public void onAnimationStart( Animation animation ) 
			{
				aquery.id( R.id.splash_title ).visible().animate( R.anim.fadein_short );
			}
			
			@Override
			public void onAnimationRepeat( Animation animation ) 
			{

			}
			
			@Override
			public void onAnimationEnd( Animation animation ) 
			{
				com.virtual.rerijaapps.pet.PrincipalScreen_.intent( splash ).start();
				splash.finish();
			}
		} );
		
		aquery.id( viewId ).visible().animate( animation );
	}

	public static class RerijaMatrixAnimation extends Animation 
	{
		@Override
		protected void applyTransformation( float interpolatedTime, Transformation t ) 
		{
			super.applyTransformation( interpolatedTime, t );
			final Matrix matrix = t.getMatrix();
			matrix.setScale( interpolatedTime, interpolatedTime );
		}
	}

}
